def write_file():
    file = None
    try:
        file = open("haha.txt","w")
        a = 20
        b = 0
        rst =a / b 
        file.write(f"hahaha:{rst}")
        print("无异常,执行代码1")
    except Exception as e:
        print("出现异常",type(e))
    else:
        print("无异常,执行代码2")
    finally:
        if file is not None:
            file.close()
            print("关闭资源")
write_file()